﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TNOVA10
    {
        public TNOVA10()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVAFARBEN();
            DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVF = dwMaster;
            if (dwMaster != null)
            {
                FARBGRP = dwMaster["VAFFARBGRP"].ToString();
                PRART = dwMaster["VAAARTST"].ToString().PadRight(1) + TMV.VAFPART + TMV.VAFPVAR.PadRight(3) + TMV.VAFFFARBE + TMV.VAFBESCHICH + TMV.VAFDESS + TMV.VAFCOLORIT + TMV.VAFPGROE;
                KEY = dwMaster["VAFKOLL"].ToString() + dwMaster["VAFART"].ToString() + dwMaster["VAFFARBE"].ToString();
                TXTISIND = KEY.PadRight(60);
            }
            else
            {
                PRART = "";
                KEY = "";
                TXTISIND = "";
            }
        }
        public override void LOADBYAUF()
        {
            if (!IsNew)
                return;
            base.LOADBYAUF();
            if (ORDERNUM.Trim().Length < 5)
                return;
            if (ORDERNUM.Length < 39)
                return;
            KOLL = ORDERNUM.Substring(0, 5);
            ART = ORDERNUM.Substring(5, 24);
            FARBE = ORDERNUM.Substring(29, 10);
            PM["KOLL"] = ORDERNUM.Substring(0, 5);
            //PM["KM1"] = KM1;
            TMV.VAK.OnAppModeChg();
            PM["KM1"] = TMV.VAK.KM1;
            TMV.VAK.NEWVAK(PM);
        }

        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            PM["ARTST"] = ARTST;
            PM["KOLL"] = KOLL;
            PM["ART"] = ART;
            PM["FARBE"] = FARBE;
            PM["DES"] = DES;
            TMV.AUTOCHK(PM);
            string key = KOLL.PadRight(5) + ART.PadRight(24) + FARBE.PadRight(10);
            Locate("KEY", key);
        }
        public override void OnAutoChg(bool value)
        {
            if (!IsAuto)
                return;
            PM["ARTST"] = ARTST;
            PM["KOLL"] = KOLL;
            PM["ART"] = ART;
            PM["FARBE"] = FARBE;
            PM["DES"] = DES;
            TMV.AUTOCHK(PM);
            string key = KOLL.PadRight(5) + ART.PadRight(24) + FARBE.PadRight(10);
            Locate("KEY", key);
            base.OnAutoChg(value);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            if (vlaue.Length == 0)
                return; 
            ARTST = vlaue.Substring(0, 1);
            ART = vlaue.Substring(1, 20);
            FARBE = vlaue.Substring(23, 10);
            DES = vlaue.Substring(1 + 20 + 2 + 10 * 4 + 7, 20);
            FINISH = vlaue.Substring(33, 10);
            DESS = vlaue.Substring(43, 10);
            COLORIT = vlaue.Substring(53, 10);
            IsNew = true;
            PM["ARTST"] = ARTST;
            PM["KOLL"] = KOLL;
            PM["ART"] = ART;
            PM["FARBE"] = FARBE;
            PM["DES"] = DES;
            PM["FINISH"] = FINISH;
            PM["DESS"] = DESS;
            PM["COLORIT"] = COLORIT;
            TMV.AUTOCHK(PM);
            string key = KOLL.PadRight(5) + ART.PadRight(24) + FARBE.PadRight(10); 
            Locate("KEY", key);
            base.OnEXAUFChg(vlaue);
        }
         
    }
}
